<template>
  <div class="boss">
    <p>课程列表</p>
    <div class="box">
      <div
        class="curriculum"
        v-for="(item, index) in message"
        :key="item.id + index"
      >
        <div class="curriculumTop">
          <p>ID:{{ item.number }}</p>
          <input type="checkbox" v-model="arr" :value="item" />
        </div>
        <img :src="require('../../../assets/img/' + item.img)" />
        <p class="p1">{{ item.curriculumName }}</p>
        <p class="p2">报名费：{{ item.price + "元" }}</p>
        <p class="p3">销量：{{ item.sales }}本</p>
        <p class="p4">课程导师：{{ item.name }}</p>
        <p class="p5">上传时间：{{ item.date }}</p>
        <div class="btn">
          <el-button size="mini" type="primary" @click="edit(item)">
            <i class="el-icon-edit"></i>编辑
          </el-button>
          <el-button
            :plain="true"
            size="mini"
            type="info"
            @click="deleOne(item.id)"
          >
            <i class="el-icon-delete"></i>删除
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import eventBus from "../../../utils/eventBus";
export default {
  props: ["message"],
  data() {
    return {
      arr: [],
      // news: {
      //   number: "",
      //   img: "",
      //   price: "",
      //   sales: "",
      //   name: "",
      //   date: "",
      // },
    };
  },
  mounted() {
    eventBus.$on("checks", this.checkAll);
    eventBus.$on("deleAll", this.deleteAll);
  },
  methods: {
    edit(val) {
      eventBus.$emit("edit", val);
    },
    deleteAll() {
      this.$emit("deleteAll", this.arr);
    },
    open1() {
      this.$message("删除成功");
    },
    deleOne(val) {
      this.$emit("deleOne", val);
      this.open1();
    },
    checkAll(flag) {
      if (flag) {
        this.arr = this.message;
      } else {
        this.arr = [];
      }
    },
  },
};
</script>

<style lang="less" scoped
>
.boss {
  > p {
    margin-top: 20px;
    margin-bottom: 21px;
    margin-left: 35px;
    font-weight: 700;
    color: #409eff;
  }
  .box {
    display: flex;
    justify-content: start;
    flex-wrap: wrap;
    .curriculum:nth-of-type(4n) {
      margin-right: 0;
    }
    .curriculum {
      margin-right: 36px;
      .btn {
        margin-top: 18px;
        display: flex;
        justify-content: space-around;
      }
      margin-bottom: 20px;
      background-color: #fff;
      width: 290px;
      height: 330px;
      box-sizing: border-box;
      padding: 8px 12px;
      img {
        width: 266px;
        height: 128px;
      }
      .curriculumTop {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 12px;
        font-weight: 600;
      }
      .p1 {
        font-size: 14px;
        font-weight: 600;
        margin-top: 10px;
        color: #333;
      }
      .p2,
      .p3,
      .p4,
      .p5 {
        font-size: 14px;
        margin-top: 10px;
        color: #333;
      }
    }
  }
}
</style>